#include <File.h>
#include <Kernel.h>

File::File(char *n, class Filesystem *parent, u32int callbackResourceId, FileTypes type) :
  parent(parent), parentDir(NULL), callbackResourceId(callbackResourceId), type(type)
{
  if (n)
  {
    name = new char[Kernel::strlen(n)+1];
    Kernel::strcpy(name, n);
  }
  else
    name = NULL;
  // Initialise the resource and functions.
  resource = new Resource((Callable*)this);
  resource->add((Resource::Call0)&File::identify,        File_IF::identify);
  resource->add((Resource::Call0)&File::getName,         File_IF::getName);
  resource->add((Resource::Call0)&File::getImplDefined,  File_IF::getImplDefined);
  resource->add((Resource::Call0)&File::getResource,     File_IF::getResource);
}

bool File::open(class FileDescriptor *descriptor)
{
  ASSERT(this);
  return (bool)callResourceSys(callbackResourceId, FILE_OPEN, _implDefined, (descriptor)?(int)descriptor->resource->getId():NULL);
}

bool File::close(class FileDescriptor *descriptor)
{
  ASSERT(this);
  return (bool)callResourceSys(callbackResourceId, FILE_CLOSE, _implDefined, (descriptor)?(int)descriptor->resource->getId():NULL);
}
